package com.bianmaba.netty.client.controller;

import com.bianmaba.netty.client.core.BootNettyClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("message")
public class MessageController {
    @Autowired
    private BootNettyClient client;

    @RequestMapping("send")
    public Object send(String message, Integer loops) {
        if (loops == null) {
            loops = 1;
        }
        for (int i = 0; i < loops; i++) {
            client.channelFuture.channel().writeAndFlush(message);
        }
        return new HashMap() {{
            put("success", true);
        }};
    }
}
